/******************************************
This program is the second step, and generates estimates 
of the CTE Credential (Table 3 in the paper)



include "config.do"

#delimit ;

/***********************************************
Post file setup
************************************************/

postfile support str20 spec str3 yvar Nobs share_grad
                   using $supportdir/support_residregs.dta, replace ;
/**********************************************
Now that we have residualized everything,
we can run the actual regressions:

******************************************/


foreach regvar in national state { ;

      use $datadir/cte_resid_earn_`regvar'.dta, clear ;
      
      foreach deglvl in 01 02 03 04 { ; 

      areg resid_earn_`regvar' resid_grad_dummy resid_enrolled resid_age_*
              resid_qtr_* if deglevl_code=="`deglvl'", cluster(group) absorb(group) ;

              local beta_`regvar'_`deglvl' = _b[resid_grad_dummy] ;
              local se_`regvar'_`deglvl'   = _se[resid_grad_dummy] ;

              count if e(sample) ;
                      local Nobs = r(N) ;
              sum grad_dummy if e(sample) ;
                      local share_grad = r(mean) ;
              post support  ("`regvar'") ("lev") (`Nobs') (`share_grad') ;      

      areg resid_logearn_`regvar' resid_grad_dummy resid_enrolled
          resid_age_* resid_qtr_* if deglevl_code== "`deglvl'", cluster(group) absorb(group) ;

              local beta_log`regvar'_`deglvl' = _b[resid_grad_dummy] ;
              local se_log`regvar'_`deglvl'   = _se[resid_grad_dummy] ;

              count if e(sample) ;
                      local Nobs = r(N) ;
              sum grad_dummy if e(sample) ;
                      local share_grad = r(mean) ;
              post  support ("`regvar'") ("log") (`Nobs') (`share_grad') ;    
      } ; 
};

postclose support ; 
foreach deglvl in 01 02 03 04 { ;
    di "========== Degree Level: `deglvl' ==========";
foreach regvar in national state { ;
      
    di "========== `regvar' ==========" ;
    di %6.5f `beta_`regvar'_`deglvl'' "     (" %6.5f `se_`regvar'_`deglvl'' ")" ;
    di %6.5f `beta_log`regvar'_`deglvl'' "     (" %6.5f `se_log`regvar'_`deglvl'' ")" ;
    di "" ;
}; 
} ;
